//  在PS端通过AXI接口(GPIO_SPI_PS)模拟出一个SPI通信模块，将PS端的数据方便地搬运至PL端

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#ifndef _SPI_PS_H_
#define _SPI_PS_H_

// GPIO_SPI_PS / GPIO_SPI_PS_CTRL
#define SPI_PS_ADC2REG_CLK  1
#define SPI_PS_DAISY        2
#define SPI_PS_OS_ADDR      3

//  =============================================================================
//  旧版本
//  1.给ADC时钟转像元时钟模块进行配置
//  2.给“Daisy Chain数据准备模块”进行配置
//  3.给输出通道选择器进行配置
void set_SPI_PS_A2( uint32_t* gpio_reg, uint32_t A2 );
void set_SPI_PS_A1( uint32_t* gpio_reg, uint32_t A1 );
void set_SPI_PS_A0( uint32_t* gpio_reg, uint32_t A0 );

//  根据SPI_PS_OPT配置PL端(A2,A1,A0)，实现SPI信号的选择
void SPI_PS_MUX8( uint32_t *axi_gpio_reg, uint32_t SPI_PS_OPT );


void SPI_PS_SCLK( uint32_t *axi_gpio_reg );
void SPI_PS_RST( uint32_t *axi_gpio_reg );

void SPI_PS_SEND_DATA(  uint32_t *axi_gpio_reg,
                        uint32_t *axi_gpio2_reg, 
                        uint32_t *reg_val, 
                        uint32_t tx_num,
                        uint32_t SPI_PS_OPT );

//  =============================================================================

//  =============================================================================
//  新版本，全部有后缀_new
//  1.给CCD读出驱动配置模块进行配置
//  2.给IDELAY模块配置参数

#define SPI_PS_READOUT_DRV   1
#define SPI_PS_IDELAY_CTRL   2

void set_SPI_PS_A3_new( uint32_t* gpio_reg, uint32_t A3 );
void set_SPI_PS_A2_new( uint32_t* gpio_reg, uint32_t A2 );
void set_SPI_PS_A1_new( uint32_t* gpio_reg, uint32_t A1 );
void set_SPI_PS_A0_new( uint32_t* gpio_reg, uint32_t A0 );

void SPI_PS_MUX16_new( uint32_t *axi_gpio_reg, uint32_t SPI_PS_OPT );

void SPI_PS_SCLK_new( uint32_t *axi_gpio_reg );
void SPI_PS_RST_new( uint32_t *axi_gpio_reg );

void SPI_PS_SET_ADDR_new( uint32_t *axi_spi_ps_ctrl_reg, uint16_t addr );
void SPI_PS_SET_DATA_new( uint32_t *axi_spi_ps_data_reg, uint32_t data );

void SPI_PS_SEND_DATA_new(  uint32_t *axi_spi_ps_ctrl_reg,
                            uint32_t *axi_spi_ps_data_reg, 
                            uint32_t *reg_val, 
                            uint32_t reg_num,
                            uint32_t SPI_PS_OPT );
//  =============================================================================

#endif  // _SPI_PS_H_


